import 'package:flutter/material.dart';
import 'package:flutter_base_plugin/flutter_base_plugin.dart';
import 'package:flutter_base_plugin_example/models/category_model.dart';
import 'package:flutter_base_plugin_example/page/category/vm/categoty_view_model.dart';

import '../../config/k_color.dart';

/// @author:  JoeKai
/// @date 2022/6/27 09:06
/// @explain：

// ignore: camel_case_types, non_constant_identifier_names
Widget CategoryLeft(BuildContext context) {
  CategoryViewModel viewModel = context.watch<CategoryViewModel>();
  var leftWidth = ScreenUtil().screenWidth / 4;
  return Container(
    width: leftWidth,
    height: double.infinity,
    color: KColors.tf1f1f1,
    child: ListView.builder(
      itemCount: viewModel.dataList.length,
      padding: EdgeInsets.all(0),
      itemBuilder: (context, index) {
        return _buildItem(viewModel, index);
      },
    ),
  );
}

_buildItem(CategoryViewModel viewModel, int index) {
  CategoryModel item = viewModel.dataList[index];
  return Column(
    children: <Widget>[
      InkWell(
        onTap: () {
          viewModel.setSelectIndex(index);
        },
        child: Container(
          width: double.infinity,
          height: 84.h,
          padding: EdgeInsets.only(top: 24.h),
          child: Text("${item.cateName}", textAlign: TextAlign.center),
          color:
              viewModel.selectIndex == index ? KColors.white : KColors.tf1f1f1,
        ),
      ),
    ],
  );
}
